package com.example.demo1;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.TextView;

/**
 * 文件名	： 	PopupWindowKAnimationTest.java
 * @author	: 	lijun
 * 维护人	： 		
 * 创建时间	：	2013-4-27 上午11:18:20
 * 功能描述	:
 */
public class PopupWindowKAnimationTest extends Activity
{
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_popup);
		init();
	}
	
	private void init()
	{
		Button btn = (Button) findViewById(R.id.button);
		btn.setOnClickListener(new OnClickListener()
		{
			
			@Override
			public void onClick(View v)
			{
				showPopupWindow(createContentView(), v);
			}
		});
	}
	
	private View createContentView()
	{
		View content = LayoutInflater.from(PopupWindowKAnimationTest.this).
			inflate(R.layout.popup_layout, null);
		
		final KAnimationLayout layout = (KAnimationLayout) content.findViewById(R.id.anim_layout);
		TextView text1 = (TextView) content.findViewById(R.id.text1);
		final TextView text2 = (TextView) content.findViewById(R.id.text2);
		
		text1.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				changeAnimLayout(layout, text2);
			}
		});
		
		return content;
	}
	
	private void showPopupWindow(View view, View anchor)
	{
		CustomPopupWindow2 window = new CustomPopupWindow2(anchor);
		window.setContentView(view);
		window.showDropDown();
	}
	
	private void changeAnimLayout(KAnimationLayout layout, final TextView text)
	{
		if (!layout.isExpanded())
		{
			text.setVisibility(View.VISIBLE);
			layout.expandAnimation(new Runnable()
			{
				public void run()
				{
				}
			});
		}
		else
		{
			layout.shrinkAnimation(new Runnable()
			{
				public void run()
				{
					text.setVisibility(View.GONE);
				}
			});
		}
	}
	
}
